package nuc.soft.xsf.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import nuc.soft.xsf.model.Paper;
import nuc.soft.xsf.model.PaperProject;
import nuc.soft.xsf.model.UserPaper;
import nuc.soft.xsf.service.IPaperProjectService;
import nuc.soft.xsf.service.IPaperService;
import nuc.soft.xsf.service.IProjectTestService;
import nuc.soft.xsf.service.IUserPaperService;
import nuc.soft.xsf.tools.Tools;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/ProjectPaperController")
public class ProjectPaperController {
	@Resource
	private IProjectTestService projectService;

	@Resource
	private IPaperProjectService paperProjectService;
	
	@Resource
	private IPaperService paperService;
    
	@Resource
	private IUserPaperService userPaperService;
	@RequestMapping(value = "/findByCondition.action", produces = "text/html;charset=utf-8")
	@ResponseBody
	public String finByCondition(PaperProject paperProject,HttpServletRequest request) {
		Map map = Tools.transBean2Map(paperProject);
		List<PaperProject> list = paperProjectService.findByCondition(map);
		List<Paper> listPaper=new ArrayList();
		int userId=(int) request.getSession().getAttribute("UserId");
		JSONObject json=new JSONObject();
		for(int i=0;i<list.size();i++){
			Paper paper=paperService.findById(list.get(i).getPaperId());
			UserPaper userPaper=new UserPaper();
			userPaper.setUserId(userId);
			userPaper.setPaperId(paper.getPaperId());
			Map map01=Tools.transBean2Map(userPaper);
			List<UserPaper> list01=userPaperService.findByCondition(map01);
			System.out.println("list01"+list01);
			if(list01!=null&&list01.size()>0){
				json.put("status","(已测评)");
			}
			else{
				json.put("status", "(未测评)");
			}
			
			listPaper.add(paper);
		}
     	json.put("list",listPaper);
		return json.toString();
	}


}
